<!-- <!doctype html> -->
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>享送小哥</title>
    <link rel="stylesheet" type="text/css" href="../css/aui.css" />
    <link rel="stylesheet" type="text/css" href="../css/style.css" />
    <link rel="stylesheet" type="text/css" href="../css/add-style.css" />
    <style>
        .aui-dialog-body {
            display: none;
        }

        .aui-dialog-header {
            padding: 1rem 0.75rem;
        }

        .aui-dialog-footer .aui-dialog-btn:nth-child(1) {
            color: #333;
        }
    </style>
</head>

<body>
    <div class="aui-content vue" id="sidebar-aside">
        <div id="mainHead">
            <div class="u-head" id="header">
                <a href="javascript:;" class="nav-bar1" @click="openHome"></a>
                <a href="javascript:;" class="u-head-addr">{{city}}<img src="../images/arr.png" class="u-addrimg" style="display:none;"></a>
                <a href="javascript:;" class="nav-bar2" @click="openMessage"></a>
            </div>
            <div class="aui-tab deliv-tab" id="deliv-tab">
                <div class="aui-tab-item aui-active">同城享送</div>
                <div class="aui-tab-item">跨城送货</div>
            </div>
        </div>

    </div>

    <!--计价总和-->
    <!-- <div class="pay-sum" id="pay-sum">
        <ul class="pay-sum1">
            <li>
                <div class="pay-l">标志起步价</div>
                <div class="pay-r">18.00元</div>
            </li>
            <li>
                <div class="pay-l">高价值保障</div>
                <div class="pay-r">+2.00元</div>
            </li>
            <li>
                <div class="pay-l">动态溢价</div>
                <div class="pay-r">+1.80元</div>
            </li>
            <li class="pay-line"></li>
            <li>
                <div class="pay-l">合计</div>
                <div class="pay-r">21.80元</div>
            </li>
        </ul>
        <a href="javascript:void(0);" class="pay-close" id="pay-close"></a>
    </div> -->
    <!--js-->
    <script type="text/javascript" src="../script/jquery-1.7.1.min.js"></script>
    <script type="text/javascript" src="../script/api.js"></script>
    <script type="text/javascript" src="../script/vue.js"></script>
    <script type="text/javascript" src="../script/app.js"></script>
    <!--选项卡-->
    <script type="text/javascript" src="../script/aui-tab.js"></script>
    <script type="text/javascript">
        var statusBarPos, mainHeadPos, headerPos;
        apiready = function() {

            vObj = new Vue({
                el: ".vue",
                data: {
                    city: "定位中",
                    location: {
                        lon: 0,
                        lat: 0
                    }
                },
                methods: {
                    openHome: function() {
                        api.openDrawerPane({
                            type: 'left'
                        });
                    },
                    openMessage: function() {
                        if ($api.getStorage('is_login') == 1) {
                            app.page({
                                name: 'message',
                                url: 'message.html'
                            });
                        } else {
                            app.error("请先登录！");
                        }
                    }
                }
            })

            var ajpush = api.require('ajpush');
            if (api.systemType == 'android') {
                ajpush.init(function(ret) {
                    if (ret && ret.status) {}
                });
            }

            ajpush.setListener(
                function(ret) {
                    var id = ret.id;
                    var title = ret.title;
                    var content = ret.content;
                    var extra = ret.extra;

                    api.confirm({
                        title: '推送消息',
                        msg: content,
                        buttons: ['查看', '关闭']
                    }, function(ret, err) {
                        var index = ret.buttonIndex;
                        if (index == 1) {
                            api.closeWin({
                                name: extra.name
                            });

                            setTimeout(function() {
                                app.page(extra)
                            }, 1000);
                        }
                    });
                }
            );

            api.addEventListener({
                name: 'appintent'
            }, function(ret, err) {
                if (ret && ret.appParam.ajpush) {
                    var ajpush = ret.appParam.ajpush;
                    api.closeWin({
                        name: ajpush.extra.name
                    });

                    setTimeout(function() {
                        app.page(ajpush.extra)
                    }, 1000);
                }
            })
            api.addEventListener({
                name: 'noticeclicked'
            }, function(ret, err) {
                if (ret && ret.value) {
                    var ajpush = ret.value;
                    var content = ajpush.content;
                    api.closeWin({
                        name: ajpush.extra.name
                    });

                    setTimeout(function() {
                        app.page(ajpush.extra)
                    }, 1000);
                }
            })

            statusBarPos = app.statusBar.pos();
            mainHeadPos = app.pos('mainHead');
            headerPos = app.pos('header');

            init();

            var tab = new auiTab({
                element: document.getElementById("deliv-tab"),
            }, function(ret) {
                api.setFrameGroupIndex({
                    name: 'tab',
                    index: ret.index - 1
                });
            });

            api.addEventListener({
                name: 'keyback'
            }, function(ret, err) {
                api.toLauncher();
                return false;
            });




            api.addEventListener({
                name: 'locationSuccess'
            }, function(ret, err) {
                if (ret) {
                    var lon = ret.value.lon;
                    var lat = ret.value.lat;
                    var ret = ret.value.ret;
                    vObj.location = {
                        lon: lon,
                        lat: lat
                    }
                    vObj.city = ret.city;

                    api.openFrameGroup({
                        name: 'tab',
                        rect: {
                            x: 0,
                            y: statusBarPos.h + mainHeadPos.h,
                            w: 'auto',
                            h: 'auto'
                        },
                        scrollEnabled: false,
                        frames: [{
                            name: 'main_city1',
                            url: 'main_city1.html',
                            bounces: false,
                            pageParam: {
                                ret: ret,
                                statusBarPos: statusBarPos,
                                headerPos: headerPos
                            }
                        }, {
                            name: 'main_city2',
                            url: 'main_city2.html',
                            bounces: false,
                            pageParam: {
                                ret: ret,
                                statusBarPos: statusBarPos,
                                headerPos: headerPos
                            }
                        }]
                    }, function(ret, err) {
                        $("#deliv-tab div:eq(" + ret.index + ")").addClass("aui-active").siblings().removeClass("aui-active");
                    });
                }
            });

            api.addEventListener({
                name: 'pause'
            }, function(ret, err) {
                ajpush.clearNotification({
                    id: -1
                }, function(ret) {
                    if (ret && ret.status) {
                        //success
                    }
                });
                if (api.systemType == 'ios') {
                    ajpush.setBadge({
                        badge: 0
                    });
                }
            });

            setTimeout(function() {
                // return;
                app.request.post('Common/version', {}, {}, function(res) {
                    var version, url, type
                    if (api.systemType == 'ios') {
                        return false
                        version = res.data.client.ios.version
                        url = res.data.client.ios.url
                        type = 'ios'
                    } else {
                        version = res.data.client.android.version
                        url = res.data.client.android.url
                        type = 'android'
                    }
                    if (api.appVersion != version) {
                        api.openWin({
                            name: 'update',
                            url: 'update.html',
                            pageParam: {
                                type: type,
                                version: version,
                                url: url
                            },
                            slidBackEnabled: false
                        });
                    }
                })
            }, 1000)
        }

        function init() {
            api.showProgress({
                title: '正在定位',
                text: '请稍候...',
                modal: true
            });
            app.lbs.init(function() {
                app.lbs.getLocation(function(lon, lat) {
                    app.lbs.getAddress(lon, lat, function(ret) {
                        api.hideProgress();
                    })
                });
            });
        }
    </script>
</body>

</html>
